package com.xbx.admin.service.dictionary.impl;

import com.xbx.common.utils.EntityUtils;
import com.xbx.common.utils.ObjectUtils;
import com.xbx.admin.entity.dictionary.res.DictionaryVo;
import com.xbx.admin.mapper.DictionaryDOMapper;
import com.xbx.admin.service.dictionary.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 字典管理实现
 *
 * @author 89005691
 * @create 2018-09-04 14:18
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private DictionaryDOMapper dictionaryDOMapper;

    @Override
    public List<DictionaryVo> selectDictionaryList(String dicKey) {

        DictionaryDOExample example = new DictionaryDOExample();
        DictionaryDOExample.Criteria criteria = example.createCriteria();

        criteria.andDicKeyEqualTo(dicKey);
        criteria.andStatusEqualTo(true);

        List<DictionaryDO> dictionaryDOS = this.dictionaryDOMapper.selectByExample(example);

        if(ObjectUtils.isNotNull(dictionaryDOS)){

            DictionaryDO dictionaryDO = dictionaryDOS.get(0);

            DictionaryDOExample example1 = new DictionaryDOExample();
            DictionaryDOExample.Criteria criteria1 = example1.createCriteria();

            criteria1.andParentIdEqualTo(dictionaryDO.getId());
            criteria1.andStatusEqualTo(true);

            return EntityUtils.transform(this.dictionaryDOMapper.selectByExample(example1), DictionaryVo.class);
        }

        return new ArrayList();
    }
}
